/*

glog封装类

使用方法

    # 基本用法
        #include "GLogHelper.h"

        std::wstring exePath = GetExecutablePath();
	    std::string  strLogPath = wstringTostring(exePath) + "/Log/agent_" + GenerateLogFileName();

	    GLogHelper& glogHelper = GLogHelper::Instance();
	    glogHelper.InitLog(true, strLogPath);

        LOG_INFO << "This is a INFO message.";
        LOG_WARNING << "This is a WARNING message.";
        LOG_ERROR << "This is a ERROR message.";

        std::string str1 = "test std::string log";
        LOG_INFO << str1;

        int age = 20;
        LOG_INFO << "age = " << age;
    
    # 调整log输出等级
        // 设置日志等级
	    FLAGS_minloglevel = 0; // 0, 1, 2 对应 INFO  WARNING ERROR
*/

#define GLOG_NO_ABBREVIATED_SEVERITIES

#pragma once
#include <glog/logging.h>
#include "CustomLogSink.h"
#include "fmt/core.h"

#define LOG_INFO LOG(INFO)
#define LOG_WARNING LOG(WARNING)
#define LOG_ERROR LOG(ERROR)
#define LOG_FATAL LOG(FATAL)

#define LOG_INFO_FMT(format_str, ...) LOG(INFO) << fmt::format(format_str, ##__VA_ARGS__)
#define LOG_WARN_FMT(format_str, ...) LOG(WARNING) << fmt::format(format_str, ##__VA_ARGS__)
#define LOG_ERROR_FMT(format_str, ...) LOG(ERROR) << fmt::format(format_str, ##__VA_ARGS__)
#define LOG_FATAL_FMT(format_str, ...) LOG(FATAL) << fmt::format(format_str, ##__VA_ARGS__)

enum class OutputType { Console = 0, File = 1, ConsoleAndFile = 2 };

class GLogHelper {
  private:
    GLogHelper();

  public:
    GLogHelper(const GLogHelper&) = delete;
    GLogHelper& operator=(const GLogHelper&) = delete;

    static GLogHelper& Instance() {
        static GLogHelper instance;
        return instance;
    }

    ~GLogHelper();

    // singleLog: true每天生成一个log, false按照运行时间点生成log
    // log_fileName: log文件名
    void InitLog(bool singleLog = true,
                 OutputType type = OutputType::Console,
                 const std::string& log_fileName = "");

  private:
    CustomLogSink* custom_sink;
};

inline void SdkAutoInit() {
    static bool dummy = ([]() {
        GLogHelper::Instance().InitLog(true, OutputType::Console, "/tmp/sdk_auto.log");
        return true;
    })();
}

// 确保静态库引用头文件就初始化
static bool _sdk_auto_init_guard = (SdkAutoInit(), true);
